@extends('admin::public.base')

@section('content')
    <div class="layui-card">
            <div class="layui-header">
        <div class="layui-card-header layuiadmin-card-header-auto">
                <a class="layui-btn" href="{{ route('admin.message.create') }}">添 加</a>
        </div>
    </div>
            <table id="dataTable" class="layui-hide" lay-filter="dataTable"></table>
            <script type="text/html" id="options">
                @{{# if(d.status == 1){ }}
                    <a class="normal" lay-event="edit">编辑</a>
                @{{# } }}
                <a class="normal" lay-event="detail">查看</a>
                <a class="normal" lay-event="del">删除</a>
            </script>
    </div>
@endsection

@section('script')
    {{--@can('system.role')--}}
    <script>
        layui.use(['layer','table','form'],function () {
            var layer = layui.layer;
            var form = layui.form;
            var table = layui.table;
            var param = {!!$param!!};
            var page = param.page?param.page:1;
            var limit = param.limit?param.limit:10;
            //用户表格初始化
            var dataTable = table.render({
                elem: '#dataTable'
                ,url: "{{ route('admin.message.getList') }}" //数据接口
                ,skin:'line'
                ,cellMinWidth: 150
                ,text: { //自定义文本，此处用法--》当返回数据为空时的异常提示
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                }
                ,page: {
                    curr:page,
                    limit:limit
                } //开启分页
                ,cols: [[ //表头
                    {checkbox: true}
                    ,{field: 'title',align:'center',  title: '消息标题'}
                    ,{field: 'content',align:'center',  title: '消息描述'}
                    ,{field: 'type_msg', align:'center', title: '消息类型'}
                    ,{field: 'send_msg', align:'center', title: '消息状态',templet: function(row) {
                        if(row.status==1){
                            return '<span style="color:#28Bc5B">'+row.send_msg+'</span>';
                        }else if(row.status==2){
                            return '<span style="color:#108cee">'+row.send_msg+'</span>';
                        }else{
                            return '<span style="color:#Ea2e2e">'+row.send_msg+'</span>';
                        }
                    }}
                    ,{field: 'user_type_msg', align:'center', title: '发送群体'}
                    ,{field: 'send_time',align:'center',  title: '发送时间'}
                    ,{field: 'create_time',align:'center',  title: '创建时间'}
                    ,{field: 'update_time',align:'center',  title: '更新时间'}
                    ,{title: '操作',align:'center', toolbar: '#options'}
                ]]
            });
            //监听复选框
            table.on('checkbox(dataTable)', function(obj){
                if(obj.checked){
                    if(obj.type=="all"){
                        $('.layui-table').find('tbody tr').attr({"style":"background:#f5fbff"});
                    }else{
                        var index = obj.data.LAY_TABLE_INDEX;
                        $('.layui-table').find('tbody tr').eq(index).attr({"style":"background:#f5fbff"});
                    }
                }else{
                    if(obj.type=="all"){
                        $('.layui-table').find('tbody tr').attr({"style":"background:#ffffff"});
                    }else{
                        var index = obj.data.LAY_TABLE_INDEX;
                        $('.layui-table').find('tbody tr').eq(index).attr({"style":"background:#ffffff"});
                    }
                }
            });
            //监听工具条
            table.on('tool(dataTable)', function(obj){ //注：tool是工具条事件名，dataTable是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    ,layEvent = obj.event; //获得 lay-event 对应的值
                if(layEvent === 'del'){
                    layer.confirm('您确认要删除吗？',{ icon: 3, title: '温馨提示', skin: 'layui-skin'}, function(index){
                        $.post("{{ route('admin.message.destroy') }}",{_method:'delete',ids:[data.id]},function (data) {
                            if (data.code == 1) {
                                layer.msg(data.msg, {
                                    time: 2000
                                }, function () {
                                    reload();
                                })
                            } else {
                                layer.msg(data.msg);
                            }
                            layer.close(index);
                        });
                    });
                } else if(layEvent === 'edit'){
                    location.href = '/admin/message/'+data.id+'/edit';
                }else if(layEvent === 'detail'){
                    location.href = '/admin/message/'+data.id+'/detail';
                }
            });
            function reload(){
                dataTable.reload({
                    page:{curr:1}
                })
            }
        })
    </script>
    {{--@endcan--}}
@endsection
